import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * Creater with IntelliJ IDEA.
 * Description:
 * User: 86152
 * Dae: 2022-07-30
 * Time: 23:45
 */
class MyThreadPool {
    BlockingQueue<Runnable> queue = new LinkedBlockingDeque<>();
    public void submit(Runnable command) {
        try {
            queue.put(command);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    public MyThreadPool(int n) {
        //创建线程
        for(int i=0;i<n;i++) {
            Thread t = new Thread(()-> {
               while(true) {
                   try {
                       Runnable runnable = queue.take();
                       runnable.run();
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }
               }
            });
            t.start();
        }
    }
}
public class demo5 {
    public static void main(String[] args) {
        MyThreadPool myThreadPool = new MyThreadPool(10);
        for(int i=0;i<100;i++) {
            myThreadPool.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("nt");
                }
            });
        }
    }
}
